package com.object.overlay;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

@SuppressWarnings("rawtypes")
public class MyItemizedOverlay extends ItemizedOverlay {

	protected ArrayList overlays;
	Context context;
	
	public MyItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		this.context = context;
		overlays = new ArrayList<OverlayItem>();
	}

	@SuppressWarnings("unchecked")
	public void addOverlay(OverlayItem overlay) {
		overlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return (OverlayItem) overlays.get(i);
	}

	@Override
	public int size() {
		return overlays.size();
	}
	
    @Override
    protected boolean onTap(final int index) {
        OverlayItem me = (OverlayItem) overlays.get(index);
        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
        dialog.setTitle(me.getTitle());
        dialog.setMessage(me.getSnippet());
        dialog.setNegativeButton("OK", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return true;
    }
}
